﻿using PLC.Domain.Dto;
using PLC.Domain.Entity;
using PLC.Domain.Enum;

namespace PLC.Domain.Models;
/// <summary>
/// plc配置对象
/// </summary>
public class PLCConfig
{
    public DeviceConfig DeviceConfig { get;  set; }
    public List<DtoDataConfig> DataConfigs { get;  set; }
    public List<DtoDataConfig> ReadDataConfigs { get;  set; }
    public List<DtoDataConfig> WriteDataConfigs { get;  set; }
    public List<DtoDataConfig> TriggerDataConfigs { get;  set; }
    public PLCConfig SetDeviceConfig(DeviceConfig deviceConfig)
    {
        this.DeviceConfig = deviceConfig;
        return this;
    }

    public PLCConfig SetDataConfigs(List<DtoDataConfig> dataConfigs)
    {
        this.DataConfigs = dataConfigs;
        return this;
    }
    /// <summary>
    /// 处理DataConfigs中的数据  给他们分组
    /// </summary>
    /// <returns></returns>
    public PLCConfig HandleDataConfigs()
    {
        this.WriteDataConfigs =  this.DataConfigs.Where(p => p.ConfigType == (int)EnumConfigType.写入).ToList();
        this.ReadDataConfigs = this.DataConfigs.Where(p => p.ConfigType == (int)EnumConfigType.读取).ToList();
        this.TriggerDataConfigs = this.DataConfigs.Where(p => p.ConfigType == (int)EnumConfigType.触发).ToList();
        return this;
    }
}